#include <sdk.h>
#include "editwatchdlg.h"
#include "debugger_defs.h"

EditWatchDlg::EditWatchDlg( cb::shared_ptr<GDBWatch> w, wxWindow* parent ) : m_watch( w ) {
  wxXmlResource* xml_res = wxXmlResource::Get();
  wxString resPath = ConfigManager::GetDataFolder() + _T( "/edit_watches_dlg.xrc" ) ;
  xml_res->Load( resPath );
  if( !xml_res->LoadObject( this, parent, _T( "dlgEditWatch" ), _T( "wxScrollingDialog" ) ) ) {
    return;
  }
  if( m_watch ) {
    wxString symbol;
    m_watch->GetSymbol( symbol );
    XRCCTRL( *this, "txtKeyword", wxTextCtrl )->SetValue( symbol );
    XRCCTRL( *this, "rbFormat", wxRadioBox )->SetSelection( ( int )m_watch->GetFormat() );
    XRCCTRL( *this, "chkArray", wxCheckBox )->SetValue( m_watch->IsArray() );
    XRCCTRL( *this, "spnArrStart", wxSpinCtrl )->SetValue( m_watch->GetArrayStart() );
    XRCCTRL( *this, "spnArrCount", wxSpinCtrl )->SetValue( m_watch->GetArrayCount() );
  }
  XRCCTRL( *this, "txtKeyword", wxTextCtrl )->SetFocus();
  XRCCTRL( *this, "wxID_OK", wxButton )->SetDefault();
}

EditWatchDlg::~EditWatchDlg() {
}

void EditWatchDlg::EndModal( int retCode ) {
  if( retCode == wxID_OK && m_watch ) {
    m_watch->SetSymbol( CleanStringValue( XRCCTRL( *this, "txtKeyword", wxTextCtrl )->GetValue() ) );
    m_watch->SetFormat( ( WatchFormat )XRCCTRL( *this, "rbFormat", wxRadioBox )->GetSelection() );
    m_watch->SetArray( XRCCTRL( *this, "chkArray", wxCheckBox )->GetValue() );
    m_watch->SetArrayParams( XRCCTRL( *this, "spnArrStart", wxSpinCtrl )->GetValue(),
                             XRCCTRL( *this, "spnArrCount", wxSpinCtrl )->GetValue() );
  }
  wxScrollingDialog::EndModal( retCode );
}
